<?php

namespace App\Console\Commands;

use App\Haha;
use Illuminate\Console\Command;

class HahaCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'haha';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $haha = Haha::all();
        foreach ($haha as $item) {

            $start = substr($item->mobile, 0, 3);
            $end = substr($item->mobile, -4, 4);
            $customer = \App\Customer::where('mobile', 'like', $start . '%' . $end)->first();
            if ($customer){
                $item->name=$customer->name;
                $item->mobile1=$customer->mobile;
                $item->save();
                $this->info($item->id);
            }
        }
    }
}
